package com.yxb.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.order.domain.TeachingOrder;
import com.yxb.order.service.ITeachingOrderService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 教学订单合约Controller
 * 
 * @author 林德炫
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/order/order")
public class TeachingOrderController extends BaseController
{
    @Autowired
    private ITeachingOrderService teachingOrderService;

    /**
     * 查询教学订单合约列表
     */
    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingOrder teachingOrder)
    {
        startPage();
        List<TeachingOrder> list = teachingOrderService.selectTeachingOrderList(teachingOrder);
        return getDataTable(list);
    }

    /**
     * 导出教学订单合约列表
     */
    @PreAuthorize("@ss.hasPermi('order:order:export')")
    @Log(title = "教学订单合约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingOrder teachingOrder)
    {
        List<TeachingOrder> list = teachingOrderService.selectTeachingOrderList(teachingOrder);
        ExcelUtil<TeachingOrder> util = new ExcelUtil<TeachingOrder>(TeachingOrder.class);
        util.exportExcel(response, list, "教学订单合约数据");
    }

    /**
     * 获取教学订单合约详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(teachingOrderService.selectTeachingOrderByOrderId(orderId));
    }

    /**
     * 新增教学订单合约
     */
    @PreAuthorize("@ss.hasPermi('order:order:add')")
    @Log(title = "教学订单合约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingOrder teachingOrder)
    {
        return toAjax(teachingOrderService.insertTeachingOrder(teachingOrder));
    }

    /**
     * 修改教学订单合约
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "教学订单合约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingOrder teachingOrder)
    {
        return toAjax(teachingOrderService.updateTeachingOrder(teachingOrder));
    }

    /**
     * 删除教学订单合约
     */
    @PreAuthorize("@ss.hasPermi('order:order:remove')")
    @Log(title = "教学订单合约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(teachingOrderService.deleteTeachingOrderByOrderIds(orderIds));
    }
}
